-module(model_adm_user).

-export([
    get/1
    ,get_by_account/1
    ,login_after/1
]).


get(Id) ->
    db_mysql:select_map_one("SELECT * FROM `adm_user` WHERE `id`=?", [Id]).

get_by_account(Account) ->
    db_mysql:select_map_one("SELECT * FROM `adm_user` WHERE `account`=?", [Account]).

login_after(AdmUser = #{login_times := LoginTimes}) ->
    Unixtime = util_time:unixtime(),
    ok = db_mysql:update("UPDATE `adm_user` SET `login_at`=?,login_times=?", [Unixtime, LoginTimes + 1]),
    AdmUser#{login_at => Unixtime, login_times => LoginTimes + 1}.
